$(document).ready(function() 
{
    
    $('#parent_id').change(function() {
        var url = $.param({
            module:     'gallery', 
            service:    'positions', 
            parent_id:  $('#parent_id option:selected').val(), 
            id:         $('#id').val()
        });
        
        $.getJSON(
            '?' + url,
            function(response) 
            {
                var target = $('#position');
                
                target.empty();
                $.each(response.positions, function(value, name) {
                    target.append('<option value="' + value + '">' + name + '</option>');
                });
                target.attr('selectedIndex', response.position - 1);
            });
    }).change();
    
});